package persistence;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import entidade.Bebida;

public class BebidaDao {
	
	protected Criteria cri;
	protected Session session;
	protected Transaction trs;
	
	public void cadastrarBebida(Bebida bebida)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.save(bebida);
		trs.commit();
		session.close();
	}
		
	@SuppressWarnings("unchecked")
	public List<Bebida> consultarBebidas() throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		cri = session.createCriteria(Bebida.class);
		return cri.list();
	}
	
	public void atualizarBebida(Bebida bebida)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.update(bebida);
		trs.commit();
		session.close();
	}
	
	public void deletarBebida(Bebida bebida)throws Exception{
		session = HibernateUtil.getSessionFactory().openSession();
		trs = session.beginTransaction();
		session.delete(bebida);
		trs.commit();
		session.close();
	}

}
